Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
Display a number with two decimals to the user without changing the original precise value [javascript]

Say for example I the following decimal value:

let myDecimal = 117.049701384;

I want to show the user 117.05 but without changing the original precise value above.

Basically what I want is to mimic Excel behaviour with decimals, where it displays a number with two decimals but holds all the decimals for math operations.

The reason I want to do this is because I want to keep the UI clean of huge decimals numbers, but also keeping the math operations that I have to perform as precise as possible. I guess I can duplicate variables but that sounds cumbersome and tedious.

Is that posible in Javascript?

I am using Javascript and VueJS 2.x in this App.

Thanks in advance.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Of course, you can use method toFixed().

For example:

let myDecimal = 117.049701384;
console.log(myDecimal.toFixed(2)); // 117.05

over 4 years ago · Santiago Trujillo Denunciar

0

use this where you return the mydecimal value back for the ui

mydecimal.tofixed(2)

over 4 years ago · Santiago Trujillo Denunciar

0

Something like this?

document.querySelectorAll("span[data-value]")
  .forEach(span => span.textContent = (+span.dataset.value).toFixed(2)); // or the VUE equivalent
<span data-value="117.049701384"></span><br/>
<span data-value="217.01384"></span>

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda